using System;
using IStrong.EC.Abstractions.Interfaces;
using IStrong.EC.DAO.Abstractions.Interfaces;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System.Linq;
using IStrong.EC.ExtensionMethods;
using System.Collections.Generic;
using IStrong.EC.WebApi.Results.Entity;

namespace IStrong.EC.WebApi.Results.Repository
{
    /// <summary>
    /// 数据访问类
    /// </summary>
    public class ChannelRepository : IService
    {
        /// <summary>
        /// 数据库操作组件
        /// </summary>
        private readonly IDbContext _db;

        /// <summary>
        /// 配置信息
        /// </summary>
        private readonly IConfiguration _configuration;

        /// <summary>
        /// 日志组件
        /// </summary>
        private readonly ILogger<ChannelRepository> _logger;

        /// <summary>
        /// 注入服务
        /// </summary>
        /// <param name="db"></param>
        /// <param name="configuration"></param>
        /// <param name="logger"></param>
        public ChannelRepository(IDbContext db, ILogger<ChannelRepository> logger, IConfiguration configuration)
        {
            _db = db;
            _logger = logger;
            _configuration = configuration;
        }

        /// <summary>
        /// 获取服务合同列表信息
        /// </summary>
        public IEnumerable<Channelinfo> GetPaginList(object param)
        {
            return _db.Query<Channelinfo>("Channelinfo.s_channelinfo", param);
        }


        public IEnumerable<int> GetTotalCount(object param)
        {
            return _db.Query<int>("Channelinfo.s_channelinfo_count", param);
        }


        public IEnumerable<Channelinfo> GetChannelById(object param)
        {
            return _db.Query<Channelinfo>("Channelinfo.s_channelinfoid", param);
        }

        public IEnumerable<ChannelExportInfo> GetExportChannel(object param)
        {
            return _db.Query<ChannelExportInfo>("Channelinfo.s_channelinfo_export", param);
        }

        public int AddChannel(object param)
        {
            return _db.ExecuteScalar<int>("Channelinfo.i_channelinfo", param);
        }

        public int UpdateChannel(object param)
        {
            return _db.Execute("Channelinfo.u_channelinfo", param);
        }

        public int UpdateChannelBase(object param)
        {
            return _db.Execute("Channelinfo.u_channel_baseinfo", param);
        }

        public int UpdateChannelValue(object param)
        {
            return _db.Execute("Channelinfo.u_channel_valueinfo", param);
        }

    }
}
